home *** CD-ROM | disk | FTP | other *** search
Text File | 2000-09-28 | 4.1 KB | 150 lines | [TEXT/CWIE] |
- {
- File: MultiHider.p
-
- Contains:
-
- Written by:
-
- Copyright: Copyright © 1984-1999 by Apple Computer, Inc., All Rights Reserved.
-
- You may incorporate this Apple sample source code into your program(s) without
- restriction. This Apple sample source code has been provided "AS IS" and the
- responsibility for its operation is yours. You are not permitted to redistribute
- this Apple sample source code as "Apple sample source code" after having made
- changes. If you're going to re-distribute the source, we require that you make
- it clear in the source that the code was descended from Apple sample source
- code, but that you've made changes.
-
- Change History (most recent first):
- 8/6/1999 Karl Groethe Updated for Metrowerks Codewarror Pro 2.1
-
-
-
- }
- PROGRAM MultiHider;
-
- USES QuickDraw,Dialogs,Fonts,Windows;
-
- CONST
- itemOK = 7;
- itemCancel = 8;
- itemStat1 = 1;
- itemStat2 = 3;
- itemStat3 = 4;
- itemEdit1 = 2;
- itemEdit2 = 5;
- itemEdit3 = 6;
- itemHider = 9;
- itemHideIt = 10;
- itemMax = 10;
- VAR
- ihDialog: DialogPtr;
- itemHit: INTEGER;
- theType: INTEGER;
- theHdl: Handle;
- theBox: Rect;
- hidden: BOOLEAN;
-
-
- PROCEDURE MyDrawItem(dlg: DialogPtr; theItem: INTEGER);
- VAR
- iType: INTEGER;
- iBox: Rect;
- iHdl: Handle;
- BEGIN
- GetDialogItem(dlg, theItem, iType, iHdl, iBox);
- IF hidden THEN BEGIN
- PenMode(notPatBic);
- PenPat(qd.gray);
- BackPat(qd.gray);
- PaintRect(iBox);
- FrameRect(iBox);
-
- PenMode(patCopy);
- PenPat(qd.black);
- BackPat(qd.white);
- PenNormal;
- END;
- END;
-
-
- PROCEDURE HideEditItem(theDialog: DialogPtr; theItem: INTEGER);
- VAR
- iIndex: INTEGER;
- BEGIN
- (* Get the item information. *)
- GetDialogItem(theDialog, theItem, theType, theHdl, theBox);
-
- (* Now check to see if it is the current text item. *)
- IF DialogPeek(theDialog)^.EditField + 1 = theItem THEN BEGIN
- (* It is, so now we find the next editText item *)
- (* in the item list. Start with the one we are on.*)
- iIndex := theItem;
- REPEAT
- (* Increment to the next item, and make sure we *)
- (* don't run off the end of the item list. *)
- iIndex := iIndex + 1;
- IF iIndex > itemMax THEN iIndex := 1;
- GetDialogItem(theDialog, iIndex, theType, theHdl, theBox);
-
- (* Keep going until we find an editText item. *)
- (* NOTE: THIS CODE ASSUMES THERE IS MORE THAN *)
- (* ONE editText ITEM IN THE DIALOG. *)
- UNTIL (theType = editText);
- SelectDialogItemText(theDialog, iIndex, 0, 0);
- END;
- GetDialogItem(theDialog, theItem, theType, theHdl, theBox);
- SetDialogItem(theDialog, theItem, statText, theHdl, theBox);
- DrawDialog(theDialog);
- END;
-
-
- PROCEDURE ShowEditItem(theDialog: DialogPtr; theItem: INTEGER);
- VAR
- oldPort: GrafPtr;
- BEGIN
- GetPort(oldPort);
- SetPort(theDialog);
- GetDialogItem(theDialog, theItem, theType, theHdl, theBox);
- SetDialogItem(theDialog, theItem, editText, theHdl, theBox);
- InvalRect(theBox);
- DrawDialog(theDialog);
- SetPort(oldPort);
- END;
-
-
- BEGIN {main program}
- InitGraf (@qd.thePort); {the big five inits}
- InitFonts;
- InitWindows;
- TEInit;
- InitDialogs (nil);
-
- hidden := FALSE;
-
- ihDialog := GetNewDialog(128, NIL, WindowPtr(-1));
- GetDialogItem(ihDialog, itemHider, theType, theHdl, theBox);
- SetDialogItem(ihDialog, itemHider, theType,Handle(NewUserItemProc(@MyDrawItem)), theBox);
- ShowWindow(ihDialog);
-
- itemHit := 0;
- WHILE ((itemHit <> itemOK) AND (itemHit <> itemCancel)) DO BEGIN
- ModalDialog(nil, itemHit);
- CASE itemHit OF
- itemHideIt: BEGIN
- GetDialogItem(ihDialog, itemHit, theType, theHdl, theBox);
- hidden := NOT hidden;
- IF hidden THEN BEGIN
- SetControlValue(ControlHandle(theHdl), 1);
- HideEditItem(ihDialog, itemEdit2);
- END ELSE BEGIN
- SetControlValue(ControlHandle(theHdl), 0);
- ShowEditItem(ihDialog, itemEdit2);
- END;
- END;
- END;
- END;
-
- DisposeDialog(ihDialog);
- END.
-